import { defHttp } from '/@/utils/http/axios';
import { ErrorMessageMode } from '/#/axios';
import type { Application } from './model';

enum Api {
  // 获取应用列表
  getApplicationList = '/application/all/list',
  // 删除应用，获取应用
  application = '/application',
  // 创建应用
  createApplication = '/application/create',
  // 更新应用
  updateApplication = '/application/update',
  // 获取应用菜单树
  applicationMenuTree = '/application/menu/tree',
  // 创建应用菜单
  createApplicationMenu = '/application/menu/create',
  // 更新应用菜单
  updateApplicationMenu = '/application/menu/update',
  // 删除应用菜单
  applicationMenu = '/application/menu',
  // 获取应用操作
  applicationOperation = '/application/operation',
  // 创建应用操作
  createApplicationOperation = '/application/operation/create',
  // 更新应用操作
  updateApplicationOperation = '/application/operation/update',
  // 删除应用操作
  deleteApplicationOperation = '/application/operation/delete',
}

export function getApplicationList(mode: ErrorMessageMode = 'modal') {
  const url = Api.getApplicationList;
  return defHttp.get<Application[]>(
    { url: url },
    {
      errorMessageMode: mode,
    }
  );
}

export function getApplicationById(id: string, mode: ErrorMessageMode = 'modal') {
  const url = `${Api.application}/${id}`;
  return defHttp.get(
    { url: url },
    {
      errorMessageMode: mode,
    }
  );
}

export function deleteApplication(id: string, mode: ErrorMessageMode = 'modal') {
  const url = `${Api.application}/${id}`;
  return defHttp.delete(
    { url: url },
    {
      errorMessageMode: mode,
    }
  );
}

export function createApplication(data: Application, mode: ErrorMessageMode = 'modal') {
  const url = Api.createApplication;
  return defHttp.post(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function updateApplication(data: Application, mode: ErrorMessageMode = 'modal') {
  const url = Api.updateApplication;
  return defHttp.put(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function getApplicationMenuTree(id: string, mode: ErrorMessageMode = 'modal') {
  const url = `${Api.applicationMenuTree}/${id}`;
  return defHttp.get(
    { url: url },
    {
      errorMessageMode: mode,
    }
  );
}

export function createApplicationMenu(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.createApplicationMenu;
  return defHttp.post(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function updateApplicationMenu(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.updateApplicationMenu;
  return defHttp.put(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function delApplicationMenu(id: string, mode: ErrorMessageMode = 'modal') {
  const url = `${Api.applicationMenu}/${id}`;
  return defHttp.delete(
    { url: url },
    {
      errorMessageMode: mode,
    }
  );
}

export function getApplicationOperationList(applicationMenuId: string, mode: ErrorMessageMode = 'modal') {
  const url = `${Api.applicationOperation}/${applicationMenuId}/menu`;
  return defHttp.get(
    { url: url },
    {
      errorMessageMode: mode,
    }
  );
}

export function createApplicationOperation(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.createApplicationOperation;
  return defHttp.post(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function updateApplicationOperation(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.updateApplicationOperation;
  return defHttp.put(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function deleteApplicationOperation(ids: string[], mode: ErrorMessageMode = 'modal') {
  const url = Api.deleteApplicationOperation;
  return defHttp.post(
    { url: url, data: ids },
    {
      errorMessageMode: mode,
    }
  );
}
